﻿#ifndef __SESSION_RECYCLER_H_INCLUDED__
#define __SESSION_RECYCLER_H_INCLUDED__

#include "timer_domain.h"
#include <deque>
using std::deque;

#ifdef __cplusplus
extern "C" {
#endif

/**
 * 会话回收器
 */
class session_recycler{

public:

	static session_recycler* get_instance();
	
	static void destroy_instance();

	// 插入一个链接域到表尾
	void push_back(timer_domain& td);

	// 从表头删除一个链接域
	timer_domain* remove_front();

	// 删除一个链接域
	void remove(timer_domain& td);

	// 使一个链接域到末尾
	void reorder(timer_domain& td);

	inline bool is_empty(){
		return (head_ptr == NULL && head_ptr == NULL);
	}

	inline timer_domain* front(){
		return head_ptr;
	}

	void print_list();

private:

	session_recycler();

	~session_recycler();
	
	static session_recycler* instance;

private:

	timer_domain* head_ptr;
	timer_domain* tail_ptr;
};

#ifdef __cplusplus
}
#endif

#endif // __SESSION_RECYCLER_H_INCLUDED__
